<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/commit/head.jsp"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<link rel="stylesheet" href="css/userlist.css" />
<div class="layui-body">
	<div style="padding: 15px;">用户管理</div>
	<div class="layui-btn-group">
		<button class="layui-btn" id="add">增加</button>
		<button class="layui-btn" id="update">编辑</button>
		<button id="del" class="layui-btn">删除</button>
	</div>
	<div id="inp">
		<input id="likename" type="text" name="title" required lay-verify="required"
			placeholder="请输入查询关键字" autocomplete="off" class="layui-input-block">&nbsp;&nbsp;
		<button id="likebutten" class="layui-btn">查询</button>
	</div>
	<table class="layui-table">
		<colgroup>
			<col width="60">
			<col width="100">
			<col width="100">
			<col width="120">
			<col width="150">
			<col width="150">
			<col>
		</colgroup>
		<thead>
			<tr>
				<th>选择</th>
				<th>用户名</th>
				<th>角色</th>
				<th>会员类型</th>
				<th>推荐人用户名</th>
				<th>状态(启用/禁用)</th>
				<th>最后修改时间</th>
			</tr>
		</thead>
		<tbody id="tbody">

		</tbody>
	</table>
	<button class="layui-btn" id="frist">首页</button>
	<button class="layui-btn" id="pre">
		<i class="layui-icon" >&#xe65a;</i>
	</button>
	<span id="span">
	</span>
	<button class="layui-btn" id="next">
		<i class="layui-icon" >&#xe65b;</i>
	</button>
	<button class="layui-btn" id="last">尾页</button>
	<input type="text" id="pageinput">
	<button class="layui-btn" id="pagebutton">GO!</button>
</div>
<form id="fm" style="display:none" class="layui-form" action="user/doadd.html" method="post" enctype="multipart/form-data">
			 <div class="layui-form-item">
			    <div class="layui-inline">
			      <label class="layui-form-label">用户角色：</label>
			      <div class="layui-input-inline">
			        <select name="roleid" >
						<option value="1">会员</option>
						<option value="2">管理员</option>
						<option value="11">其他</option>
			        </select>
			      </div>
			    </div>
			    <div class="layui-inline">
			      <label class="layui-form-label">会员类型：</label>
			      <div class="layui-input-inline">
			        <select name="usertype" lay-search="" lay-verify="required">
						<option value="0">注册会员</option>
						<option value="1">消费会员</option>
						<option value="2">vip会员</option>
						<option value="3">加盟店</option>
			        </select>
			      </div>
			    </div>
			  </div>
			  
			<div class="layui-form-item">
			    <div class="layui-inline">
			      <label class="layui-form-label">用户名：</label>
			      <div class="layui-input-inline">
			        <input id="code" name="logincode" class="layui-input" type="text" autocomplete="off" lay-verify="required" >
			      </div>
			      <span id="namecheck"></span>
			    </div>
			    <div class="layui-inline">
			      <label class="layui-form-label">姓名：</label>
			      <div class="layui-input-inline">
			        <input name="username" class="layui-input" type="text" autocomplete="off" lay-verify="required" >
			      </div>
			    </div>
			</div>
		
			<div class="layui-form-item">
			    <div class="layui-inline">
			      <label class="layui-form-label">证件类型：</label>
			      <div class="layui-input-inline">
			        <select name="cardtype">
						<option value="0">二代身份证</option>
						<option value="1">护照</option>
						<option value="2">军官证</option>
			        </select>
			      </div>
			    </div>
			    <div class="layui-inline">
			      <label class="layui-form-label">证件号码：</label>
			      <div class="layui-input-inline">
			        <input name=idcard class="layui-input" type="text" autocomplete="off" lay-verify="required|identity" >
			      </div>
			    </div>
			</div>
			
			<div class="layui-form-item">
			    <div class="layui-inline">
			      <label class="layui-form-label">收获国家：</label>
			      <div class="layui-input-inline">
			        <select name="country">
						<option value="0">中国</option>
						<option value="1">美国</option>
			        </select>
			      </div>
			    </div>
			    <div class="layui-inline">
			      <label class="layui-form-label">移动电话：</label>
			      <div class="layui-input-inline">
			        <input name="mobile" class="layui-input" type="text" autocomplete="off" lay-verify="required|phone" >
			      </div>
			    </div>
			</div>
			
			<div class="layui-form-item">
			    <div class="layui-inline">
			      <label class="layui-form-label">电子邮件：</label>
			      <div class="layui-input-inline">
			        <input name="email" class="layui-input" type="text" lay-verify="email|required" autocomplete="off" >
			      </div>
			    </div>

			<div class="layui-form-item">
			    <div class="layui-inline">
			      <label class="layui-form-label">开户行：</label>
			      <div class="layui-input-inline">
			        <input name="postcode" class="layui-input" type="text" autocomplete="off" lay-verify="required" >
			      </div>
			    </div>
			    <div class="layui-inline">
			      <label class="layui-form-label">开户卡号：</label>
			      <div class="layui-input-inline">
			        <input name="bankaccount" class="layui-input" type="text" autocomplete="off" lay-verify="required" >
			      </div>
			    </div>
			</div>
			
			<div class="layui-form-item">
				<label class="layui-form-label">开户人：</label>
				<div class="layui-input-block">
					<input type="text" name="accountholder"  autocomplete="off" lay-verify="required" class="layui-input">
				</div>
			</div>
			
			<div class="layui-form-item">
				<label class="layui-form-label">上传身份证图片（正反面）：</label>
				<div class="layui-input-block">
					<input type="file" name="partFile1"  autocomplete="off" lay-verify="required" class="layui-input">
				</div>
			</div>
			
			<div class="layui-form-item">
				<label class="layui-form-label">上传银行卡图片：</label>
				<div class="layui-input-block">
					<input type="file" name="partFile2"  autocomplete="off" lay-verify="required" class="layui-input">
				</div>
			</div>
			
		<div class="layui-form-item">
				<div class="layui-input-block">
					<input id="save" type="submit" lay-submit  class="layui-btn layui-btn-radius" value="保存" >
<!-- 					<input id="close" type="button" class="layui-btn layui-btn-radius" value="关闭" >
 -->				</div>
			</div>

		</form>
		
		
<script src="./layer/layer.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/js/adduser.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/js/updateuser.js"></script>

<script type="text/javascript">

$("#close").click(function(){
	console.log("1111");
	$("#fm").hide(); 
	
})
	$("#code").blur(function(){
			var name=$(this).val();
			
			$.post("user/serchByName.html","name="+name,function(check){
				if(check==0){
					layer.tips('用户名已被使用', '#namecheck');
					$("#namecheck").css("color","red");
					$("#save").attr("disabled",true);
				}else{
					layer.tips('用户名可以使用', '#namecheck');
					
					$("#namecheck").css("color","green");
					$("#save").attr("disabled",false);
				}
			})
			
		}) 

</script>
<script type="text/javascript">

	$(function() {
		var page = {};
		$.post("user/listAll.html", "", function(data) {
			page = data;
			console.log(page);
			show(page);
		}, "json");

		function show(page) {
			$("#tbody").html("");
			$("#span").html("");
			var list = page.list;
			for ( var i in list) {
				$("#tbody").append($("<tr id="+list[i].id+">"));
				$("#" + list[i].id).append($("<td>").append($("<input type='radio' name='xuance' id=radio"+list[i].id+" />")));
				$("#" + list[i].id).append($("<td>").html(list[i].username));
				$("#" + list[i].id).append($("<td>").html(list[i].roleid));
				$("#" + list[i].id).append($("<td>").html(list[i].usertypename));
				$("#" + list[i].id).append($("<td>").html(list[i].retercode));
				$("#" + list[i].id).append($("<td>").append($("<input type='checkbox' name='xuance' id=box"+list[i].id+" />")));
				var start = list[i].isstart;
				if (start == 1) {
					$("#box" + list[i].id).prop("checked", true);
				} else {
					$("#box" + list[i].id).prop("checked", false);
				}
				$("#" + list[i].id).append(
						$("<td>").html(list[i].lastupdatetiame));
			}
			for(i=1;i<=page.pages;i++){
				$("#span").append($("<button class='layui-btn' id='page"+i+"'>").html(i))
			}
			
		}
		$("#tbody").on("click",":checkbox",function() {
					var cb = $(this).parent().parent().attr("id");
					var s = null;
					if ($(this).prop("checked")) {
						s = 1;
					} else {
						s = 0;
					}
					$.post("user/updateAuthority.html", "id=" + cb + "&start="+ s, function() {

					});
				});
		
		$("#last").click(function(){
			$.post("user/listAll.html","pageIndex="+page.lastPage+"&name="+$("#likename").val(), function(data) {
				page = data;
				show(page);
			}, "json");
		});
		$("#frist").click(function(){
			$.post("user/listAll.html","pageIndex=1"+"&name="+$("#likename").val(), function(data) {
				page = data;
				show(page);
			}, "json");
		});
		$("#pre").click(function(){
			$.post("user/listAll.html","pageIndex="+page.prePage+"&name="+$("#likename").val(), function(data) {
				page = data;
				show(page);
			}, "json");
		});
		$("#next").click(function(){
			$.post("user/listAll.html","pageIndex="+page.nextPage+"&name="+$("#likename").val(), function(data) {
				page = data;
				show(page);
			}, "json");
		});
		
/* 		<c:forEach var="t" begin="1" end="${page.pages}">
			$("#page"+${t}).click(function(){
			$.post("user/listAll.html","pageIndex="+${t}, function(data) {
				console.log(page);
				page = data;
				show(page);
			}, "json");
		});
		</c:forEach> */
		$("#span").on("click","button",function(){
			$.post("user/listAll.html","pageIndex="+$(this).html()+"&name="+$("#likename").val(), function(data) {
				page = data;
				show(page);
			}, "json");
		})
		
		$("#pagebutton").click(function(){
			$.post("user/listAll.html","pageIndex="+$("#pageinput").val()+"&name="+$("#likename").val(), function(data) {
				page = data;
				show(page);
			}, "json");
			
		});
		
		$("#likebutten").click(function(){
			$.post("user/listAll.html","pageIndex="+$("#pageinput").val()+"&name="+$("#likename").val(), function(data) {	
				page = data;
				show(page);
			}, "json");
			
		});
		
		$("#del").click(function(){
			layer.confirm('您确定要删除吗？', {
				  btn: ['就要删，谁都拦不了我','不，我点错了'], //按钮
				  move: false,
				  offset: '70px',
	  			area: ['350px', '200px']
				}, function(){
					$(":radio").each(function(){
						if($(this).prop("checked")){
							var cb = $(this).parent().parent().attr("id");
							window.location.href="user/del.html?id="+cb
						}
					}) 
				}, function(){
				  
				});
			
		})
	});

console.info(11111);
layui.use(['form'], function(){

	var form =layui.form;
	console.info(form);
	form.verify({
		logincode: function(name,value){
	
		}
	});
});	
</script>
<%@include file="/WEB-INF/commit/dibu.jsp"%>